<?php
/**
 * Name:Xml输出类类
 * Version:1.0
 * Author:阳光男孩
 * Author QQ:51154393
 * Author Url:www.uephp.com
**/
namespace Ue\tools;
class Xml{
    private $version  = '1.0';
    private $encoding  = 'UTF-8';
    private $root    = 'Uephp';
    private $xml    = null;
	
    function __construct(){
        $this->xml = new \XmlWriter();
    }
	
    function toXml($data){
		$this->xml->openMemory();
		$this->xml->startDocument($this->version, $this->encoding);
		$this->xml->startElement($this->root);
        
        foreach($data as $key => $value){
            if(is_array($value)){
                $this->xml->startElement($key);
                $this->toXml($value, TRUE);
                $this->xml->endElement();
                continue;
            }
            $this->xml->writeElement($key, $value);
        }
        
		header("Content-type:text/xml");//输出xml头信息
		$this->xml->endElement();
		echo $this->xml->outputMemory(true);
		exit;
        
    }
}
?>